﻿Imports System.Data
Imports System.Collections
Public Class frm_SalesOrder

    Dim arr_Controls As ArrayList
    Private Sub btn_Outlet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Outlet.Click
        Dim f_Outlet As New popup_Outlet
        If f_Outlet.ShowDialog() = Windows.Forms.DialogResult.OK Then
            setOutlet(f_Outlet.dg_Outlet.Item(f_Outlet.dg_Outlet.CurrentRowIndex, 0), f_Outlet.dg_Outlet.Item(f_Outlet.dg_Outlet.CurrentRowIndex, 1))            
        End If
    End Sub
    Public Sub setOutlet(ByVal cardCode As String, ByVal cardName As String)
        PublicVariables.cur_CardCode = cardCode
        btn_Outlet.Text = cardName
        btn_Add.Enabled = True
    End Sub

    Private Sub frm_SalesOrder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        arr_Controls = New ArrayList()

        btn_Add.Enabled = False
        btn_Save.Enabled = False
    End Sub


    Private Sub btn_Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Add.Click
        Dim newUC As New uc_ItemDetail
        newUC.Tag = arr_Controls.Count
        newUC.Top = arr_Controls.Count * newUC.Height
        newUC.btn_Item.Focus()
        arr_Controls.Add(newUC)
        pn_Data.Controls.Add(newUC)
        btn_Save.Enabled = True
    End Sub

    Private Sub arrangeData()
        pn_Data.Controls.Clear()
        Dim cX As Integer = 0
        For Each uc As uc_ItemDetail In arr_Controls
            uc.Top = cX
            pn_Data.Controls.Add(uc)
            cX = cX + uc.Height
        Next

    End Sub
    'Private Sub arrangeData()
    '    pn_Data.Controls.Clear()
    '    pn_Data.Controls.Clear()
    '    Dim x As Integer = 0
    '    For Each row As DataRow In dt_SalesOrder.Rows
    '        Dim uc As New uc_ItemDetail
    '        uc.Top = x
    '        uc.Left = 0
    '        uc.Tag = row("ID")
    '        uc.btn_Item.Text = row("itmName")
    '        uc.txt_Qty.Text = row("qty")
    '        uc.txt_Price.Text = row("price")
    '        uc.txt_Total.Text = row("total")
    '        pn_Data.Controls.Add(uc)
    '        x = x + uc.Height
    '    Next
    'End Sub

    Private Sub btn_Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Save.Click

    End Sub

    Private Sub btn_Delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Delete.Click
        For Each uc As uc_ItemDetail In arr_Controls.ToArray
            If uc.chk_Select.Checked Then
                arr_Controls.Remove(uc)
            End If
        Next
        arrangeData()
    End Sub
End Class